package com.niit.agricstore.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.niit.agricstore.entity.AfterSale;
import com.niit.agricstore.entity.Product;
import com.niit.agricstore.mapper.AftersaleMapper;
import com.niit.agricstore.service.AftersaleService;
import com.niit.agricstore.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
@Slf4j
public class AftersaleServiceImpl implements AftersaleService {
    @Autowired
    private AftersaleMapper aftersaleMapper;
    //查询售后数据
    @Override
    public AfterSale getAftersaleById(int aftersale_id) {
        return aftersaleMapper.findById(aftersale_id);
    }
    //查询所有售后记录
    @Override
    public PageInfo<AfterSale> findAllByPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<AfterSale> list = aftersaleMapper.findAllByPage();
        log.info("==============list=================="+ list);
        PageInfo pageInfo = new PageInfo<>(list);
        System.out.println("分页信息"+pageInfo);
        return pageInfo;
    }

    //更新售后状态
    @Override
    public Result updateAftersaleStatus(int aftersale_id, String aftersale_state) {
        Result result = new Result();
        try {
            aftersaleMapper.updateStatus(aftersale_id, aftersale_state);
            result.setCode(String.valueOf(200));
            result.setMsg("更新成功");
        } catch (Exception e) {
            result.setCode(String.valueOf(500));
            result.setMsg("更新失败");
        }
        return result;
    }
}
